package com.crazy.bookstore.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.crazy.bookstore.common.ApiRestResponse;
import com.crazy.bookstore.entity.Book;
import com.crazy.bookstore.service.BookService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author: 卢辉宇
 * @date: 2022/12/27 21:41
 * @description:
 */
@RestController
@RequestMapping("/book")
public class BookController {
    @Resource
    BookService bookService;

    /**
     * 分页查询
     * @param categoryId
     * @param order
     * @param page
     * @return
     */
    @GetMapping("/list")
    public ApiRestResponse list(Long categoryId, String order, Integer page){
        IPage<Book> iPage = bookService.selectPage(categoryId, order, page, 10);
        return ApiRestResponse.seccess(iPage);
    }

    /**
     * 通过id查找书本
     * @param bookId
     * @return
     */
    @GetMapping("/detail")
    public ApiRestResponse detail(Long bookId){
        //调用service的查询业务。。。。
        Book book = bookService.selectById(bookId);
        return ApiRestResponse.seccess(book);
    }

}
